//
//  LLSearchBar.swift
//  新浪微博
//
//  Created by mac on 16/5/22.
//  Copyright © 2016年 mac.com. All rights reserved.
//

import UIKit
class LLSearchBar: UIView {
    @IBOutlet weak var searchText: UITextField!
    @IBOutlet weak var cancelBtn: UIButton!
    @IBOutlet weak var rightCon: NSLayoutConstraint!
    class  func loadSearchBar() -> LLSearchBar{
    
    let searchBar =  NSBundle.mainBundle().loadNibNamed("LLSearchBar", owner: nil, options: nil).last as! LLSearchBar
        return searchBar
    
    }
    override func awakeFromNib() {
        self.bounds.size.width = ScreenWidth
        searchText.leftView = UIImageView (image: UIImage(named: "searchbar_textfield_search_icon"))
        searchText.leftViewMode = .Always
        searchText.leftView?.frame = CGRectMake(0, 0, 50, 40)
        searchText.leftView?.contentMode = .Center
    }
    
   
    
    @IBAction func cancelBtnDidClick(sender: AnyObject) {
        self.rightCon.constant = 0
        UIView.animateWithDuration(0.25) {
            self.layoutIfNeeded()
        }
        self.endEditing(true)
    }
    @IBAction func textFiledBeginEditing(sender: AnyObject) {
        UIView.animateWithDuration(0.25){
            self.rightCon.constant = self.cancelBtn.bounds.width
            self.layoutIfNeeded()
        
        }

    }
    
    
}
